<template>
    <div>
        <header class="resviseTop">
            <img src="../../images/left.png" alt="" onClick="javascript :history.back(-1);">
            <span class="resvise_title">提现</span>
        </header>
        <div class="bg_fff">
            <div class="W_90">
                <div class="top_zhanghao" v-if="users.user_open_id">
                    <img src="../../img_myself/wx.png" alt="" class="wximg">
                    <div>
                        <span>账号</span>
                        <p>{{ users.user_mobile }}</p>
                    </div>
                    <div>
                        <span>微信</span>
                        <p>{{ users.user_open_id }}</p>
                    </div>
                    <img src="../../img_myself/bang.png" alt="" class="R_img">
                    <img src="../../img_myself/border.png" alt="" class="left_border">
                    <img src="../../img_myself/border.png" alt="" class="right_border">
                </div>
                <!--<div v-else  class="top_zhanghao" >-->
                    <!--<img src="../../img_myself/wx.png" alt="" class="wximg">-->
                    <!--<button>立即绑定</button>-->
                    <!--<div>-->
                        <!--<span>账号</span>-->
                        <!--<p>{{ users.user_mobile }}</p>-->
                    <!--</div>-->
                    <!--<img src="../../img_myself/border.png" alt="" class="left_border">-->
                    <!--<img src="../../img_myself/border.png" alt="" class="right_border">-->
                <!--</div>-->
                <div class="change_Money">
                    <ul>
                        <li v-for="(arr,index) in tasks.withdraw_buttons" :class="{'active':clicked==arr}"
                            @click="Change_Click(arr)">{{arr}}金币
                        </li>
                    </ul>
                    <p>可提现余额 {{ users.user_balance }} 金币</p>
                </div>
            </div>
        </div>
        <div class="Put_money">
            <div class="putBtn">
                <div @click="PutMoneyBtn">申请提现</div>
                <p @click="putMoney">提现记录</p>
            </div>
            <div class="rule">
                <p>提现规则</p>
                <div>
                    <textarea name="" id="" cols="30" rows="10" :value="tasks.withdraw_rules" disabled="disabled"></textarea>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import api from '../../utils/api';

    import { MessageBox } from 'mint-ui'
    export default {
        name: "putMoney",
        data: () => ({
            clicked: 5,   //标识，初始化默认选中第一项
            tasks: [],
            users: []
        }),
        methods: {
            Change_Click: function (index) {
                this.clicked = index
            },
            PutMoneyBtn: function () {
                var _that = this;
                // MessageBox.prompt('请输入提现密码',{inputType: 'password',showCancelButton: true}).then(({ value, action }) => {
                //     if(isNaN(value) || value.length != 6) {
                //         _that.$toast('请输入正确密码')
                //         return false;
                //     }
                //
                // });
                MessageBox.confirm('确定要申请提现吗?').then(action => {
                    var params = {
                        withdraw_amount: _that.clicked,
                        payment_id: 1,
                    }
                    api.request('/capitals/withdraw', 'post', params).then((resp) => {
                        _that.$toast('申请提现成功')
                        api.request('/user', 'get', {}).then((resp) => {
                            _that.users = resp.data.data;
                        })
                    })
                });

                // if (Math.round(this.put_money * 100) / 100 <= Math.round(this.Myselfmoney * 100) / 100) {
                //     alert('提现成功')
                // } else {
                //     alert('提现失败')
                // }
            },
            putMoney: function () {
                this.$router.push({
                    name: 'Commission',
                    params: {
                        num: 2
                    }
                })
            },
        },
        mounted() {
            document.body.scrollTop = 0;

        },
        created() {
            api.request('/common', 'get', {}).then((resp) => {
                this.tasks = resp.data.data
            })
            api.request('/user', 'get', {}).then((resp) => {
                this.users = resp.data.data
                this.clicked = this.users.withdraw_buttons[0]
            })

        }
    }
</script>

<style scoped="css">
    @import "../../style/putMoney.css";
</style>
